package com.tjsinfo.tjsoa.workplan.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.common.PageController;
import com.tjsinfo.tjsoa.system.vo.User;
import com.tjsinfo.tjsoa.workplan.bo.IWorkPlanDefineBo;

/**
 * 领导检查默认的工作计划
 * @author wangxiaowei
 *
 */
public class CheckDefalntWorkPlanAction extends Action{
	private IWorkPlanDefineBo workPlanDefineBo;
	/* (non-Javadoc)
	 * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	
	/**
	 * @return the workPlanDefineBo
	 */
	public IWorkPlanDefineBo getWorkPlanDefineBo() {
		return workPlanDefineBo;
	}
	/**
	 * @param workPlanDefineBo the workPlanDefineBo to set
	 */
	public void setWorkPlanDefineBo(IWorkPlanDefineBo workPlanDefineBo) {
		this.workPlanDefineBo = workPlanDefineBo;
	}
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		try {
			HttpSession session = request.getSession();
			User user = (User) session.getAttribute("user");
			List list = 	workPlanDefineBo.selectDefineAndType(user.getUser_id());
			Integer contentspage = null;
			String start = null;
			 PageController pageController = new PageController();
			    if(request.getParameter("page") != null && request.getParameter("start") == null )
				{
					pageController.setPageController(list);
					pageController.setMaxPageRows(18);
					list = (ArrayList) pageController.getPageContents(Integer.parseInt(request.getParameter("page") ));
			
				}
			    else if (request.getParameter("page") != null) {
					contentspage = Integer.parseInt(request.getParameter("page"));
					start = request.getParameter("start");
					pageController.setPageController(list);
					pageController.setMaxPageRows(18);
					if (start.equals("up")) {
						list = (ArrayList) pageController
								.getPageContents(contentspage - 1);
					} else if(start.equals("down")) {
						list = (ArrayList) pageController
								.getPageContents(contentspage + 1);
					}
					else if(start.equals("first"))
					{
						list = (ArrayList) pageController
						.getPageContents(1);
					}
					else if(start.equals("last"))
					{
						list = (ArrayList) pageController
						.getPageContents(pageController.getPageCount());
					}
				} else {
					pageController.setPageController(list);
					pageController.setMaxPageRows(18);
					list = (ArrayList) pageController.getPageContents(1);
				}
			request.setAttribute("list", list);
			request.setAttribute("pageController",pageController);
			return mapping.findForward("ok");
			
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();
			return mapping.findForward("error");
		}
		
	}
}
